﻿// ================================================================================
//        File: FormatManager.cs
//        Desc: 数据转换成相应的格式
//        Auth: Alex
//        Date: 2010-09-17
// ================================================================================
//        Change History
// ================================================================================
//        Date:         Author:                  Description:
//        --------     --------              -------------------
//              
// ================================================================================


using System;
using System.Collections.Generic;
using System.Text;

namespace EShop.Common
{
    public static class FormatManager
    {
        private const string DateFormat = "dd MMM yyyy";
        private const string DateFormatForFinance = "yyyy-MM-dd";
        private const string DateTimeFormat = "dd MMM yyyy HH:mm";
        private const string DateTimeFormats = "dd MMM yyyy HH:mm:ss";
        private const string CurrencyFormat = "#,##0.00;(#,##0.00)";
        //private const string CurrencyFormat = "$#,##0.00;($#,##0.00)";
        private const string DecimalFormat = "#,##0.00;(#,##0.00)";
        private const string IntegerFormat = "#,##0;(#,##0)";
        private const string PercentFormat = "##0.00%";
        private const string ShortTimeFormat = "HH:mm:ss";
        private const string DecimalFormatAmt = "###0.00";


        /// <summary>
        /// dd MMM yyyy
        /// </summary>
        public static string FormatDate(DateTime dt)
        {
            return dt.ToString(DateFormat);
        }

        /// <summary>
        /// yyyy-MM-dd
        /// </summary>
        public static string FormatDateForFinance(DateTime dt)
        {
            return dt.ToString(DateFormatForFinance);
        }

        /// <summary>
        /// dd MMM yyyy HH:mm
        /// </summary>
        public static string FormatDateTime(DateTime dt)
        {
            return dt.ToString(DateTimeFormat);
        }

        /// <summary>
        /// dd MMM yyyy HH:mm:ss
        /// </summary>
        public static string FormatDateTimes(DateTime dt)
        {
            return dt.ToString(DateTimeFormats);
        }

        /// <summary>
        /// HH:mm:ss
        /// </summary>
        public static string FormatShortTime(DateTime dt)
        {
            return dt.ToString(ShortTimeFormat);
        }

        /// <summary>
        /// $#,##0.##;($#,##0.##)
        /// </summary>
        public static string FormatCurrency(decimal o)
        {
            return o.ToString(CurrencyFormat);
        }

        /// <summary>
        /// #,##0.00
        /// </summary>
        public static string FormatDecimal(decimal o)
        {
            return o.ToString(DecimalFormat);
        }

        /// <summary>
        /// ###0.00
        /// </summary>
        public static string FormatDecimalAmt(decimal o)
        {
            return o.ToString(DecimalFormatAmt);
        }

        /// <summary>
        /// #,##0;(#,##0)
        /// </summary>
        public static string FormatInteger(int i)
        {
            return i.ToString(IntegerFormat);
        }

        /// <summary>
        /// ##0.00%
        /// </summary>
        public static string FormatPercent(decimal o)
        {
            return o.ToString(PercentFormat);
        }

        public static decimal RoundCurrency(decimal o)
        {
            return Math.Round(o, 2);
        }
    }
}
